<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2019/7/18
  Time: 14:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript"  src="js/jquery.min.js"></script>
    <script>
        $(function(){
                console.log("hh");
                $("#btn1").click(function(){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/jsontest",
                        method:"POST",
                        dataType:"json",
                        contentType : "application/json;charset=UTF-8",
                        <!-- 向后端传输的数据 -->
                        data : JSON.stringify({
                            id : $("#id").val(),
                            password : $("#password").val()
                        }),
                        success:function(result) {
                            <!-- 处理后端返回的数据 -->
                            var message = eval(result);
                            $("#id").val(message.name);
                            $("#password").val(message.password);
                            console.log("success")
                        },
                        error:function(result){
                            $("#select-box").html("查询失败");
                            console.log("failed: " + result)
                        }
                    });
                });
        });


    </script>


</head>
<body>
<form>
    用户名：<input id="id" type="text"> </br>
    密码：<input id="password" type="text"> </br>
    <button id="btn1" type="button"> check </button>
</form>

</body>
</html>
